home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / ShapePart Browser ƒ / AutoMouse.c next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  2.7 KB  |  143 lines  |  [TEXT/KAHL]

  1. /*
  2.  *    AutoMouse.c
  3.  *
  4.  *    Robert Dierkes,  April 26, 1993
  5.  *
  6.  *    Change History:
  7.  *
  8.  *       4/93    ???        New
  9.  *       4/96    bob        Updated #includes to support changed GX Library names.
  10.  *                    Changed fixed to Fixed.
  11.  *                    Changed fract to Fract.
  12.  *                    Changed boolean to Boolean.
  13.  *                    Added the copyright info.
  14.  *
  15.  *
  16.  *        © Apple Computer, Inc. 1990 - 1996  All rights reserved
  17.  *
  18.  */
  19.  
  20. /*------------------*/
  21. /*    Include Files    */
  22. /*------------------*/
  23. #include <GXMath.h>
  24. #include <GXGraphics.h>
  25. #include <GXEnvironment.h>
  26.  
  27. #include "AutoMouse.h"
  28.  
  29.  
  30. /*----------------------*/
  31. /*    Global Declarations    */
  32. /*----------------------*/
  33. Boolean        gMoveMouse,
  34.             gFirstTime;
  35. Fixed        gDegrees;
  36. long        gScale;
  37. Point        gPosition,
  38.             gLocalCenter,
  39.             gCenter;
  40.  
  41.  
  42. /*------------------------------*/
  43. /*    External Declarations     */
  44. /*------------------------------*/
  45.  
  46.  
  47. #define    MTemp        0x0828
  48. #define    RawMouse    0x082C
  49. #define    CrsrCouple    0x08CF
  50. #define    CrsrNew        0x08CE
  51.  
  52. #define    MTempL        (*((long *) MTemp))
  53. #define    RawMouseL    (*((long *) RawMouse))
  54.  
  55. #define    CrsrCoupleB    (*((char *) CrsrCouple))
  56. #define    CrsrNewB    (*((char *) CrsrNew))
  57.  
  58. #define    SetMousePosition(p)    {MTempL = RawMouseL = *((long *) p); CrsrNewB = CrsrCoupleB;}
  59.  
  60.  
  61. void InitializeAutoMouse (gxShape boundsShape)
  62. {
  63.     gxRectangle    bounds;
  64.  
  65.     gMoveMouse = false;
  66.     gFirstTime = true;
  67.     gDegrees   = 0;
  68.  
  69.     GXGetShapeBounds (boundsShape, 0, &bounds);
  70.  
  71.     /* Assumes the bounds are square */
  72.     gScale = FixedToInt (bounds.right - bounds.left) / 2;
  73.  
  74.     /* Get center of boundsShape */
  75.     gLocalCenter.h = gScale + FixedToInt (bounds.left);
  76.     gLocalCenter.v = gScale + FixedToInt (bounds.top);
  77.  
  78.     gScale -= 16;
  79. }
  80.  
  81.  
  82. Boolean ToggleAutoMouse (void)
  83. {
  84.     /*    Is gPosition outside bounds of boxes?
  85.             Move mouse inside bounds
  86.     */
  87.  
  88.     if (gMoveMouse = ! gMoveMouse)
  89.     {
  90.         /* Adjust center point if window was moved */
  91.         gCenter  = gLocalCenter;
  92.         LocalToGlobal (&gCenter);
  93.  
  94.         gFirstTime = true;
  95.     }
  96.  
  97.     return (! gMoveMouse);
  98. }
  99.  
  100.  
  101. #undef    kShowMousePath
  102. #define    kDegreesAdvance    fixed1>>6
  103.  
  104. #define FractToFix(a)    ((Fixed)(a) >> 14)
  105.  
  106. void MoveAutoMouse (void)
  107. {
  108.     Fract    cosine,
  109.             sine;
  110.  
  111.     if (! gMoveMouse)
  112.         return;
  113.  
  114.     /* Stop the automated mouse if user the moved mouse */
  115.     if (gFirstTime)
  116.         gFirstTime = false;
  117.     else
  118.     {    if (RawMouseL != (*((long *) &gPosition)))
  119.         {
  120.             ToggleAutoMouse ();
  121.             return;
  122.         }
  123.     }
  124.  
  125.     /* Advance the mouse to a new position */
  126.     FractSineCosine (31 * gDegrees, &cosine);
  127.     sine = FractSineCosine (29 * gDegrees, nil);
  128.     gDegrees += kDegreesAdvance;
  129.  
  130.     gPosition.h = FixedToInt (FractToFix (cosine) * gScale) + gCenter.h;
  131.     gPosition.v = FixedToInt (FractToFix (sine)   * gScale) + gCenter.v;
  132.     SetMousePosition (&gPosition);
  133.  
  134. #ifdef    kShowMousePath
  135.     {    Point    curPosition;
  136.         curPosition = gPosition;
  137.         GlobalToLocal (&curPosition);
  138.         MoveTo (curPosition.h, curPosition.v);
  139.         Line (0, 0);
  140.     }
  141. #endif
  142. }
  143.